<template>
    <div class="app-container">
       <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="68px">
          <el-form-item label="访问地点" prop="address">
             <el-input
                v-model="queryParams.address"
                placeholder="请输入访问地点"
                clearable
                style="width: 240px"
                @keyup.enter="handleQuery"
             />
          </el-form-item>
          <el-form-item>
             <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
             <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
       </el-form>

       <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
       </el-row>

       <!-- 表格数据 -->
       <el-table v-loading="loading" :data="visitList">
          <el-table-column label="序号" prop="id" min-width="15%" />
          <el-table-column label="访问IP" prop="ip" :show-overflow-tooltip="true" min-width="25%" />
          <el-table-column label="访问地点" prop="address" :show-overflow-tooltip="true" min-width="35%" />
          <el-table-column label="访问时间" align="center" prop="createTime" min-width="25%">
             <template #default="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
             </template>
          </el-table-column>
       </el-table>
 
       <pagination
          v-show="total > 0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
       />
    </div>
</template>

<script setup name="Visit">
import { listVisit } from "@/api/system/visit";
import { getCurrentInstance, ref, reactive, toRefs } from 'vue';

const { proxy } = getCurrentInstance();

const visitList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    address: undefined
  }
});

const { queryParams } = toRefs(data);

/** 查询访问记录列表 */
function getList() {
  loading.value = true;
  listVisit(queryParams.value).then(response => {
    visitList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

getList();
</script>
 